/*
 * 百度在线网络技术（北京）有限公司拥有本软件版权2022并保留所有权利。
 * Copyright 2022, Baidu.com,Inc 2:Baidu Online Network Technology (Beijing) Co.,Ltd,
 * All rights reserved.
 */

package com.azdebugit.spring.docother.juc.syn;

import java.util.concurrent.TimeUnit;

/**
 * @author azdebugit
 * Date 2021/7/4
 * @version 1.0
 * 两个线程调用同一个对象的两个同步方法
 */
public class Lock6 {
    public static void main(String[] args) {
        //同一对象
        Number6 number = new Number6();

        //线程1
        new Thread(() -> {number.getOne();},"A").start();
        
        //线程2
        new Thread(() -> {number.getTwo();},"B").start();

    }
}

class Number6{
    //同步方法1 (static)
    public static synchronized void getOne(){
        try {
            TimeUnit.SECONDS.sleep(2);
            System.out.println(Thread.currentThread().getName() + "： one");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    //同步方法2 (static)
    public static synchronized void getTwo(){
        System.out.println(Thread.currentThread().getName() + "： two");
    }
}